﻿using ServiceReference1;
using System;
using System.Collections;
using System.Data.SqlTypes;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using XXX.Bo;
using XXX.Common;
using XXX.Models.AS;

namespace U8COWeb
{
    /// <summary>
    /// 部门档案接口
    /// </summary>
    public static class DepartmentDALCO
    {
        public static bool AddDepartment(AS_Department rdrecord,string xmlconfig, out string err, out string id)
        {
            try
            {
                string xdomhead = XmlOperation.ObjectToXmlSerializer(rdrecord);
                //类名问题，更改xml文件
                xdomhead = xdomhead.Replace("AS_Department", "Department");
                var binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = 2147483647;
                // 根据 WebService 的 URL
                var endpoint = new EndpointAddress(CanShu.coUrl);
                // 创建调用接口的工厂，注意这里泛型只能传入接口
                var factory = new ChannelFactory<WebService1Soap>(binding, endpoint);
                // 从工厂获取具体的调用实例
                var callClient = factory.CreateChannel();
                // 调用具体的方法，这个地方就看你都有啥方法啦，自行替换
                //var request = new SendFormatSMSRequest(sendFormatSMSRequestBody);

                var result = callClient.execAsync("AS", "department", "add", "", xdomhead, "", "", xmlconfig, "config").Result;

                string ccode = "";
                return XmlOperation.GetCoResult("部门档案新增", "0", out err, out id, out ccode, result);
            }
            catch (Exception ex)
            {
                id = "";
                err = ex.Message;
                return false;
            }
        }

        public static bool ModifyDepartment(AS_Department rdrecord,string xmlconfig,  out string err, out string id)
        {
            try
            {
                string xdomhead =XmlOperation.ObjectToXmlSerializer(rdrecord);
                //类名问题，更改xml文件
                xdomhead = xdomhead.Replace("AS_Department", "Department");
               var binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = 2147483647;
                // 根据 WebService 的 URL
                var endpoint = new EndpointAddress(CanShu.coUrl);
                // 创建调用接口的工厂，注意这里泛型只能传入接口
                var factory = new ChannelFactory<WebService1Soap>(binding, endpoint);
                // 从工厂获取具体的调用实例
                var callClient = factory.CreateChannel();
                // 调用具体的方法，这个地方就看你都有啥方法啦，自行替换
                //var request = new SendFormatSMSRequest(sendFormatSMSRequestBody);

                var result = callClient.execAsync("AS", "department", "modify", rdrecord.cDepCode, xdomhead, "", "", xmlconfig, "config").Result;
  
                string ccode = "";
                return XmlOperation.GetCoResult("部门档案修改", "0", out err, out id, out ccode, result);
            }
            catch (Exception ex)
            {
                err = ex.Message;
                id = "";
                return false;
            }
        }
        public static bool DelDepartment(string cDepCode, string xmlconfig, out string err)
        {
            try
            {
                var binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = 2147483647;
                // 根据 WebService 的 URL
                var endpoint = new EndpointAddress(CanShu.coUrl);
                // 创建调用接口的工厂，注意这里泛型只能传入接口
                var factory = new ChannelFactory<WebService1Soap>(binding, endpoint);
                // 从工厂获取具体的调用实例
                var callClient = factory.CreateChannel();
                // 调用具体的方法，这个地方就看你都有啥方法啦，自行替换
                //var request = new SendFormatSMSRequest(sendFormatSMSRequestBody);

                var result = callClient.execAsync("AS", "department", "delete", cDepCode, "", "", "", xmlconfig, "config").Result;
                string id = "";
                string ccode = "";
                return XmlOperation.GetCoResult("部门档案删除", "0", out err, out id, out ccode, result);
            }
            catch (Exception ex)
            {
                err = ex.Message;
                return false;
            }
        }

      
    }
}
